package com.mybatis.framework.hander;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Arrays;

import com.mybatis.framework.anno.Select;
import com.spring.mybatis.demo.Model.Student;
import com.spring.mybatis.demo.Model.User;


/**
 * com.mybatis.framework.hander
 *
 * @author humdeef
 * @since 2019-07-14
 */
public class MybatisInvocationHandler implements InvocationHandler {

  @Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Select select = method.getAnnotation(Select.class);
    System.out.println(select.value());
    String sql = select.value();

    // 默认db操作
    if (select.value().contains("student")) {
      return Arrays.asList(new Student(1L, "tom", "a"), new Student(2L, "jerry", "b"));
    }
    if (select.value().contains("user")) {
      return Arrays.asList(new User(1L, "tom"), new User(2L, "jerry"));
    }
    return null;
  }

}
